import 'package:word_game/engine/core.dart';
import 'kill_monster_task.dart';
import 'task.dart';
import 'taskable_hero.dart';

class AcceptEvent extends Eventable {
  AcceptEvent() : super('接受');

  @override
  void doEvent(owner) {
    var task = owner as Task;
    var hero = World.instance.hero as TaskableHero;
    task.owner.taskStates['${task.code}_${hero.name}'] = 'accept';
    Task item;
    if (task is KillMonsterTask) {
      item = KillMonsterTask(task.name);
    } else {
      item = Task(task.name);
    }
    item.copyData(task);
    item.receiver = hero;
    item.accepted();
    hero.tasks.add(item);
    if (task.initThingCode!=null && task.initThingCode.isNotEmpty) {
      hero.getThing(MaterialManager.instance.newMaterialWithCode(task.initThingCode));
    }
    Engine.instance.displayer.displayString('[${hero.name}]接受了任务[${task.name}]。');
  }
}